package com.jinxin.platform.cdfaceacs.controller;

import com.jinxin.platform.base.common.pojo.JsonResult;
import com.jinxin.platform.cdfaceacs.bean.CdzxkacsTimeTempalte;
import com.jinxin.platform.cdfaceacs.rpc.SysUserRpc;
import com.jinxin.platform.cdfaceacs.service.IAcsTimeTemplateService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * All rights Reserved, Designed By www.beonelot.com
 *
 * @version: V1.0
 * @Copyright: www.beonelot.com Inc. All rights reserved.
 * @Description：
 * @Date: 2020-12-26
 * @Author: Lingnan
 **/
@RestController
@RequestMapping("/zxkTimeTemplate")
@Slf4j
public class ZxkTimeTemplateController {
    @Autowired
    private IAcsTimeTemplateService timeTemplateService;
    @Autowired
    private SysUserRpc sysUserRpc;

    @RequestMapping("/list")
    public Map<String,Object> list(@RequestParam int page, @RequestParam int limit, String deviceId,String phone){
        HashMap param = new HashMap();
        param.put("page", page);
        param.put("limit", limit);
        param.put("deviceId", deviceId);
        param.put("phone", phone);
        Map<String,Object> resultMap = new HashMap<>();
        resultMap.put("code",0);
        resultMap.put("msg","");
        if(StringUtils.isEmpty(deviceId)){
            resultMap.put("count", 0);
            resultMap.put("data", null);
            return resultMap;
        }
        resultMap.put("count", timeTemplateService.listPageCount(param));
        resultMap.put("data", timeTemplateService.listPage(param));
        return resultMap;
    }

    @GetMapping("/listAll")
    public JsonResult listAll(String deviceId){
        if(!StringUtils.isEmpty(deviceId)){
            HashMap param= new HashMap();
            param.put("deviceId",deviceId);
            return JsonResult.ok(timeTemplateService.list(param));
        }
        return JsonResult.ok(null);
    }

    @CrossOrigin
    @PostMapping("/saveOrUpdate")
    public JsonResult saveOrUpdate(@RequestBody CdzxkacsTimeTempalte timeTempalte){
        return timeTemplateService.saveOrUpdate(timeTempalte);
    }

    @GetMapping("/getTimeTemplate")
    public JsonResult getTimeTemplate(String id){
        return JsonResult.ok(timeTemplateService.getTimeTemplate(id));
    }

    @GetMapping("/delete")
    public JsonResult delete(@RequestParam String id, @RequestParam String deviceId){
        return timeTemplateService.delete(id,deviceId);
    }

}
